/*FatFs Disk IO support for SD cards*/
#ifndef DISKIO_SD_H
#define DISKIO_SD_H

/*Modules Header files*/
#include "spi\spi.h"
#include "diskio.h"

/* Scheduler include files. */
#include "FreeRTOS.h"
#include "task.h"

/*Configurations*/
#define AMOUNT_OF_DRIVERS   4
#define DMA_DUMMY_IN_RAM    0
#define SPI_SPEED_STARTUP   0xFE
#define SPI_SPEED_FULL      0x02

/*Stat initialization macro value*/
#if   AMOUNT_OF_DRIVERS == 1
#define STAT_INITIAL_VALUE STA_NOINIT
#elif AMOUNT_OF_DRIVERS == 2
#define STAT_INITIAL_VALUE {STA_NOINIT, STA_NOINIT}
#elif AMOUNT_OF_DRIVERS == 3
#define STAT_INITIAL_VALUE {STA_NOINIT, STA_NOINIT, STA_NOINIT}
#elif AMOUNT_OF_DRIVERS == 4
#define STAT_INITIAL_VALUE {STA_NOINIT, STA_NOINIT, STA_NOINIT, STA_NOINIT}
#else
#error Amount of drivers for FatFs is not Valid
#endif

#define DMA_DUMMY_SIZE  512
#define DMA_DUMMY_INITIALIZATION                                            \
{                                                                           \
    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,  \
	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,  \
	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,  \
	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,  \
	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,  \
	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,  \
	0xFF,0xFF,0xFF,0xFF,0xFF,0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FF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,  \
	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,  \
	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF                                 \
}                                 
 
/* Definitions for MMC/SDC command */
#define CMD0	(0x40+0)	/* GO_IDLE_STATE */
#define CMD1	(0x40+1)	/* SEND_OP_COND (MMC) */
#define	ACMD41	(0xC0+41)	/* SEND_OP_COND (SDC) */
#define CMD8	(0x40+8)	/* SEND_IF_COND */
#define CMD9	(0x40+9)	/* SEND_CSD */
#define CMD10	(0x40+10)	/* SEND_CID */
#define CMD12	(0x40+12)	/* STOP_TRANSMISSION */
#define ACMD13	(0xC0+13)	/* SD_STATUS (SDC) */
#define CMD16	(0x40+16)	/* SET_BLOCKLEN */
#define CMD17	(0x40+17)	/* READ_SINGLE_BLOCK */
#define CMD18	(0x40+18)	/* READ_MULTIPLE_BLOCK */
#define CMD23	(0x40+23)	/* SET_BLOCK_COUNT (MMC) */
#define	ACMD23	(0xC0+23)	/* SET_WR_BLK_ERASE_COUNT (SDC) */
#define CMD24	(0x40+24)	/* WRITE_BLOCK */
#define CMD25	(0x40+25)	/* WRITE_MULTIPLE_BLOCK */
#define CMD55	(0x40+55)	/* APP_CMD */
#define CMD58	(0x40+58)	/* READ_OCR */

/*Macros*/
#define setTimeOut(x) usTimeout = x
#define startTimeOut(y) setTimeOut(y); vTaskResume(xDiskIOSDTimedOutHandle)
#define hasTimedOut()  (usTimeout == 0) 

#endif // DISKIO_SD_H
